package com.shop2cn.iapi.agentproducts.testcase;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonArray;
import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.EditProductRebateBean;
import com.shop2cn.iapi.agentproducts.parameter.ImportAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.ProductDetailsDto;
import com.shop2cn.iapi.agentproducts.parameter.ProductListDto;
import com.shop2cn.iapi.agentproducts.parameter.QueryProductListBeanV2;
import com.shop2cn.iapi.agentproducts.parameter.SaveSelectionConditionBean;
import com.shop2cn.iapi.agentproducts.service.QueryProductListCallV2;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.godmch.parameter.CreateCodeBean;
import com.ymatou.iapi.godmch.parameter.createDepotBean;
import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymatou.iapi.godmch.service.CreateCodeCall;
import com.ymatou.iapi.prodstock.parameter.AgentProductPo;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P2;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.godmch.mch_depot_info;
import com.ymttest.database.sqlwapper.YmtProductsIWapper;
import com.ymttest.utils.AgentUsers;
import com.ymttest.utils.TestDataManager;

/**
 * 查询商品列表 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_QueryProductListV2 {

	private static QueryProductListBeanV2 queryproductlistBeanV2;
	private static QueryProductListCallV2 queryproductlistCallV2;

	// 渠道商
	private static int sellerId = AgentUsers.rootUserId;
	private static String sellerName = "NickautoTest";
	// 渠道商->代理商1
	private static int agentUserId1 = AgentUsers.agentUserId1;
	private static String agentUserName1 = "NickautoTest";
	// 渠道商->代理商2
	private static int agentUserId2 = AgentUsers.agentUserId2;
	private static String agentUserName2 = "NickautoTest";
	// 渠道商
	private static int rootUserId = AgentUsers.rootUserId;
	private static String rootUserName = "NickautoTest";
	
	
	private static YmtProductsIWapper ymtProductsIWapper = new YmtProductsIWapper();
	

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询商品列表");
	}

	@Before
	public void caseUp() {
		queryproductlistBeanV2 = new QueryProductListBeanV2();
		queryproductlistCallV2 = new QueryProductListCallV2();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(queryproductlistCallV2.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_QueryProductList_001() {
		Logger.start(true, "根据商户id，商品id进行查询");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(sellerId,
					sellerName, false);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			queryproductlistBeanV2.setUserId(sellerId);
			queryproductlistBeanV2.setProductIdList(Arrays.asList(productId));
			queryproductlistBeanV2.setPageIndex(1);
			queryproductlistBeanV2.setPageSize(100);
			queryproductlistCallV2.setData(queryproductlistBeanV2);
			queryproductlistCallV2.callService();
			JsonArray asJsonArray = queryproductlistCallV2.getJsonObject().get("data").getAsJsonObject()
					.get("productList").getAsJsonArray();
			Logger.verifyEquals("200", queryproductlistCallV2.getJsonObject().get("code").getAsString(), "验证Code");
			Logger.verifyEquals(true, asJsonArray.size() > 0, "验证是否查询到了");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_QueryProductList_002() {
		Logger.start(true, "根据商户id上架的商品进行查询");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(sellerId,
					sellerName, false);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			queryproductlistBeanV2.setUserId(sellerId);
			queryproductlistBeanV2.setStatus(0);
			queryproductlistBeanV2.setPageIndex(1);
			queryproductlistBeanV2.setPageSize(100);
			queryproductlistCallV2.setData(queryproductlistBeanV2);
			queryproductlistCallV2.callService();
			JsonArray asJsonArray = queryproductlistCallV2.getJsonObject().get("data").getAsJsonObject()
					.get("productList").getAsJsonArray();
			Logger.verifyEquals("200", queryproductlistCallV2.getJsonObject().get("code").getAsString(), "验证Code");
			Logger.verifyEquals(true, asJsonArray.size() > 0, "验证是否查询到了");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_QueryProductList_003() {
		Logger.start(true, "根据商户id，币种进行查询");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(sellerId,
					sellerName, false);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			queryproductlistBeanV2.setUserId(sellerId);
			queryproductlistBeanV2.setCurrency("USD");
			queryproductlistBeanV2.setPageIndex(1);
			queryproductlistBeanV2.setPageSize(100);
			queryproductlistCallV2.setData(queryproductlistBeanV2);
			queryproductlistCallV2.callService();
			JsonArray asJsonArray = queryproductlistCallV2.getJsonObject().get("data").getAsJsonObject()
					.get("productList").getAsJsonArray();
			Logger.verifyEquals("200", queryproductlistCallV2.getJsonObject().get("code").getAsString(), "验证Code");
			Logger.verifyEquals(true, asJsonArray.size() > 0, "验证是否查询到了");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_QueryProductList_004() {
		Logger.start(true, "根据商户id，代理类型进行查询");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(sellerId,
					sellerName, false);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			queryproductlistBeanV2.setUserId(sellerId);
			queryproductlistBeanV2.setAgentType(0);
			queryproductlistBeanV2.setPageIndex(1);
			queryproductlistBeanV2.setPageSize(100);
			queryproductlistCallV2.setData(queryproductlistBeanV2);
			queryproductlistCallV2.callService();
			JsonArray asJsonArray = queryproductlistCallV2.getJsonObject().get("data").getAsJsonObject()
					.get("productList").getAsJsonArray();
			Logger.verifyEquals("200", queryproductlistCallV2.getJsonObject().get("code").getAsString(), "验证Code");
			Logger.verifyEquals(true, asJsonArray.size() > 0, "验证是否查询到了");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_QueryProductList_005() {
		Logger.start(true, "根据商户id，代理类型进行查询");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(sellerId,
					sellerName, false);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			queryproductlistBeanV2.setUserId(sellerId);
			queryproductlistBeanV2.setAgentType(0);
			queryproductlistBeanV2.setPageIndex(1);
			queryproductlistBeanV2.setPageSize(100);
			queryproductlistCallV2.setData(queryproductlistBeanV2);
			queryproductlistCallV2.callService();
			JsonArray asJsonArray = queryproductlistCallV2.getJsonObject().get("data").getAsJsonObject()
					.get("productList").getAsJsonArray();
			Logger.verifyEquals("200", queryproductlistCallV2.getJsonObject().get("code").getAsString(), "验证Code");
			Logger.verifyEquals(true, asJsonArray.size() > 0, "验证是否查询到了");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_QueryProductList_006() {
		Logger.start(true, "根据商户id，代理类型进行查询");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(sellerId,
					sellerName, false);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			queryproductlistBeanV2.setUserId(sellerId);
			queryproductlistBeanV2.setAgentType(0);
			queryproductlistBeanV2.setPageIndex(1);
			queryproductlistBeanV2.setPageSize(100);
			queryproductlistCallV2.setData(queryproductlistBeanV2);
			queryproductlistCallV2.callService();
			JsonArray asJsonArray = queryproductlistCallV2.getJsonObject().get("data").getAsJsonObject()
					.get("productList").getAsJsonArray();
			Logger.verifyEquals("200", queryproductlistCallV2.getJsonObject().get("code").getAsString(), "验证Code");
			Logger.verifyEquals(true, asJsonArray.size() > 0, "验证是否查询到了");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_QueryProductList_007() {
		Logger.start(true, "根据商户id，代理类型进行查询");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(sellerId,
					sellerName, false);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			queryproductlistBeanV2.setUserId(sellerId);
			queryproductlistBeanV2.setAgentType(0);
			queryproductlistBeanV2.setPageIndex(1);
			queryproductlistBeanV2.setPageSize(100);
			queryproductlistCallV2.setData(queryproductlistBeanV2);
			queryproductlistCallV2.callService();
			JsonArray asJsonArray = queryproductlistCallV2.getJsonObject().get("data").getAsJsonObject()
					.get("productList").getAsJsonArray();
			Logger.verifyEquals("200", queryproductlistCallV2.getJsonObject().get("code").getAsString(), "验证Code");
			Logger.verifyEquals(true, asJsonArray.size() > 0, "验证是否查询到了");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_QueryProductList_008() {
		Logger.start(true, "根据商户id，商品id，错误币种。让有商品id时会自动忽略其余的。查询成功");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(sellerId,
					sellerName, false);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			queryproductlistBeanV2.setUserId(sellerId);
			queryproductlistBeanV2.setProductIdList(Arrays.asList(productId));
			queryproductlistBeanV2.setCurrency("AAA");
			queryproductlistBeanV2.setPageIndex(1);
			queryproductlistBeanV2.setPageSize(100);
			queryproductlistCallV2.setData(queryproductlistBeanV2);
			queryproductlistCallV2.callService();
			JsonArray asJsonArray = queryproductlistCallV2.getJsonObject().get("data").getAsJsonObject()
					.get("productList").getAsJsonArray();
			Logger.verifyEquals("200", queryproductlistCallV2.getJsonObject().get("code").getAsString(), "验证Code");
			Logger.verifyEquals(true, asJsonArray.size() > 0, "验证是否查询到了");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_QueryProductList_009() {
		Logger.start(true, "根据商户id，商品id，错误币种。让有商品id时会自动忽略其余的。查询成功");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(sellerId,
					sellerName, false);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			queryproductlistBeanV2.setUserId(sellerId);
			queryproductlistBeanV2.setProductIdList(Arrays.asList(productId));
			queryproductlistBeanV2.setCurrency("AAA");
			queryproductlistBeanV2.setPageIndex(1);
			queryproductlistBeanV2.setPageSize(100);
			queryproductlistCallV2.setData(queryproductlistBeanV2);
			queryproductlistCallV2.callService();
			JsonArray asJsonArray = queryproductlistCallV2.getJsonObject().get("data").getAsJsonObject()
					.get("productList").getAsJsonArray();
			Logger.verifyEquals("200", queryproductlistCallV2.getJsonObject().get("code").getAsString(), "验证Code");
			Logger.verifyEquals(true, asJsonArray.size() > 0, "验证是否查询到了");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	public void Tc_QueryProductList_010() {
		Logger.start(true, "渠道商发布商品，下面自动继承的代理自动继承,判断进货价是否正确");
		try {
			// 创建两个用户
			UserCreateBean usercreateBean1 = DGUserCallService.initUsercreateBean();
			int userId_channl = DGUserCallService.UserCreateCall(usercreateBean1);
			usercreateBean1 = DGUserCallService.initUsercreateBean();
			int userId_agent = DGUserCallService.UserCreateCall(usercreateBean1);
			// 设置渠道商
			createmchBean createmchbean = GodmchManageCallService.InitcreatemchBeanForChannel(userId_channl);
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			// 给渠道商创建一个商品
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(userId_channl,
					usercreateBean1.getNickname(), true);
			double price = 200;
			addAgentProductBean.getCatalogList().forEach(a -> {
				a.setDirectPrice(price * 2);
				a.getAgentPriceList().forEach(b -> {
					b.setAgentPrice(price);
				});
			});
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(userId_channl,
					productId);
			List<String> catalogs = new ArrayList<>();
			selectProductDetails.getCatalogList().forEach(c -> {
				catalogs.add(c.getCatalogId());
			});
			Thread.sleep(5000);
			// 渠道商创建一个邀请码，出来一个自动继承的代理商、自动继承渠道商刚才的商品
			CreateCodeBean createbean = GodmchManageCallService.InitcreateCodeBeanForAgent(userId_channl);
			createbean.setAgentModel(2);// 自动继承
			CreateCodeCall CreateCodeCall = GodmchManageCallService.createCodeCall(createbean);
			List<createmchBean> createmchList = GodmchManageCallService.InitcreatemchBeanForAgent(userId_channl,
					userId_agent); //
			createmchList.get(0).setCode(CreateCodeCall.getCode());
			GodmchManageCallService
					.createmchCallForAgent(createmchList.toArray(new createmchBean[createmchList.size()]));
			Thread.sleep(5000);

			// 渠道商查询
			queryproductlistBeanV2.setUserId(userId_channl);
			queryproductlistBeanV2.setProductIdList(Arrays.asList(productId));
			queryproductlistBeanV2.setPageIndex(1);
			queryproductlistBeanV2.setPageSize(100);
			queryproductlistCallV2.setData(queryproductlistBeanV2);
			queryproductlistCallV2.callService();
			JsonArray asJsonArray = queryproductlistCallV2.getJsonObject().getAsJsonObject("data")
					.getAsJsonArray("productList").get(0).getAsJsonObject().getAsJsonArray("catalogList");
			Logger.verifyEquals("200", queryproductlistCallV2.getJsonObject().get("code").getAsString(), "验证Code");
			Logger.verifyEquals(true, asJsonArray.size() > 0, "验证是否查询到了");
			// 代理商查询

			queryproductlistBeanV2.setUserId(userId_agent);
			queryproductlistBeanV2.setProductIdList(Arrays.asList(productId));
			queryproductlistBeanV2.setPageIndex(1);
			queryproductlistBeanV2.setPageSize(100);
			queryproductlistCallV2.setData(queryproductlistBeanV2);
			queryproductlistCallV2.callService();
			JsonArray asJsonArray1 = queryproductlistCallV2.getJsonObject().getAsJsonObject("data")
					.getAsJsonArray("productList").get(0).getAsJsonObject().getAsJsonArray("catalogList");
			Logger.verifyEquals("200", queryproductlistCallV2.getJsonObject().get("code").getAsString(), "验证Code");
			Logger.verifyEquals(true, asJsonArray.size() > 0, "验证是否查询到了");

			// 判断代理提货价 与渠道商提货价
			asJsonArray.forEach(a -> {
				double asDouble = a.getAsJsonObject().get("salePrice").getAsDouble();
				double asDouble2 = a.getAsJsonObject().get("buyingPrice").getAsDouble();
				Logger.verifyEquals(price * 2, asDouble, "直销价");
				Logger.verifyEquals(0.0, asDouble2, "渠道商提货价");
			});
			asJsonArray1.forEach(a -> {
				double asDouble = a.getAsJsonObject().get("salePrice").getAsDouble();
				double asDouble2 = a.getAsJsonObject().get("buyingPrice").getAsDouble();
				Logger.verifyEquals(price * 2, asDouble, "直销价");
				Logger.verifyEquals(price, asDouble2, "代理商提货价");
			});

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_QueryProductList_011() {
		Logger.start(true, "渠道商获取商户商品列表，根据备注进行搜索商户商品列表");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(sellerId,
					sellerName, false);
			String b = "remark" + TestDataManager.getRandomNum(6);
			addAgentProductBean.setRemark(b);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			queryproductlistBeanV2.setRemark(b);
			queryproductlistBeanV2.setPageIndex(1);
			queryproductlistBeanV2.setPageSize(10);
			queryproductlistBeanV2.setUserId(sellerId);
			queryproductlistCallV2.setData(queryproductlistBeanV2);
			queryproductlistCallV2.callService();
			Logger.verifyEquals("200", queryproductlistCallV2.getString("code"), "验证code");

			System.out.println(queryproductlistCallV2.getJsonObject().toString());

			JsonArray productLists = queryproductlistCallV2.getJsonObject().getAsJsonObject("data")
					.getAsJsonArray("productList");

			Logger.verifyEquals(1, productLists.size(), "验证查询个数");
			Logger.verifyEquals(b, productLists.get(0).getAsJsonObject().get("remark").getAsString(), "验证商品id");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_QueryProductList_012() {
		Logger.start(true, "获取商品列表，根据仓库Id查询");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, true);
			createDepotBean bean = GodmchManageCallService.createDepot(rootUserId);
			List<mch_depot_info> selectDepotByDepotTitle = GodmchManageCallService
					.SelectDepotByDepotTitle(bean.getDepotTitle());
			addAgentProductBean.setDepotId(selectDepotByDepotTitle.get(0).getDepotId());
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			queryproductlistBeanV2.setPageIndex(1);
			queryproductlistBeanV2.setPageSize(10);
			queryproductlistBeanV2.setDepotId(selectDepotByDepotTitle.get(0).getDepotId());
			queryproductlistBeanV2.setUserId(rootUserId);
			queryproductlistCallV2.setData(queryproductlistBeanV2);
			queryproductlistCallV2.callService();
			Logger.verifyEquals("200", queryproductlistCallV2.getString("code"), "验证code");

			System.out.println(queryproductlistCallV2.getJsonObject().toString());
			
			JsonArray productLists = queryproductlistCallV2.getJsonObject().getAsJsonObject("data")
					.getAsJsonArray("productList");
			Logger.verifyEquals(1, productLists.size(), "验证查询个数");
			Logger.verifyEquals(productId, productLists.get(0).getAsJsonObject().get("productId").getAsString(), "验证商品id");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_QueryProductList_013() {
		Logger.start(true, "获取商品列表，根据物流方式查询");
		try {
			
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			queryproductlistBeanV2.setPageIndex(1);
			queryproductlistBeanV2.setPageSize(10);
			queryproductlistBeanV2.setDeliveryTypes(Arrays.asList(2));
			queryproductlistBeanV2.setUserId(rootUserId);
			queryproductlistCallV2.setData(queryproductlistBeanV2);
			queryproductlistCallV2.callService();
			Logger.verifyEquals("200", queryproductlistCallV2.getString("code"), "验证code");

			System.out.println(queryproductlistCallV2.getJsonObject().toString());

			JsonArray productLists = queryproductlistCallV2.getJsonObject().getAsJsonObject("data")
					.getAsJsonArray("productList");
			Logger.verifyEquals(productId, productLists.get(0).getAsJsonObject().get("productId").getAsString(), "验证商品id");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_QueryProductList_014() {
		Logger.start(true, "获取商品列表，根据最小最大库存查询");
		try {
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,
					rootUserName, true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			Thread.sleep(5000);
			queryproductlistBeanV2.setPageIndex(1);
			queryproductlistBeanV2.setPageSize(10);
			queryproductlistBeanV2.setMinStock(10);
			queryproductlistBeanV2.setMaxStock(400);
			queryproductlistBeanV2.setUserId(rootUserId);
			queryproductlistCallV2.setData(queryproductlistBeanV2);
			queryproductlistCallV2.callService();
			Logger.verifyEquals("200", queryproductlistCallV2.getString("code"), "验证code");

			System.out.println(queryproductlistCallV2.getJsonObject().toString());

			JsonArray productLists = queryproductlistCallV2.getJsonObject().getAsJsonObject("data")
					.getAsJsonArray("productList");
			Logger.verifyEquals(productId, productLists.get(0).getAsJsonObject().get("productId").getAsString(), "验证商品id");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_QueryProductList_015() {
		Logger.start(true, "获取商品列表，分销小店在规则内就显示，不在规则内就不显示");
		try {
			
			int MchId=501163195;
			int AgentId = 501163196;
			
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(MchId, "", true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			
			SaveSelectionConditionBean initSaveSelectionCondition = AddAgentProductCallService.InitSaveSelectionCondition(MchId, AgentId, 1);
			initSaveSelectionCondition.setBrandIdList(Arrays.asList(666));
			AddAgentProductCallService.SaveSelectionCondition(initSaveSelectionCondition);
			
			queryproductlistBeanV2.setPageIndex(1);
			queryproductlistBeanV2.setPageSize(10);
			queryproductlistBeanV2.setUserId(AgentId);
			queryproductlistCallV2.setData(queryproductlistBeanV2);
			queryproductlistCallV2.callService();
			Logger.verifyEquals("200", queryproductlistCallV2.getString("code"), "验证code");
			Logger.verifyEquals(0, queryproductlistCallV2.getJsonObject().getAsJsonObject("data").getAsJsonArray("productList").size(),"没有查询到");
			
			
			initSaveSelectionCondition = AddAgentProductCallService.InitSaveSelectionCondition(MchId, AgentId, 0);
			AddAgentProductCallService.SaveSelectionCondition(initSaveSelectionCondition);
			
			queryproductlistBeanV2.setPageIndex(1);
			queryproductlistBeanV2.setPageSize(10);
			queryproductlistBeanV2.setUserId(AgentId);
			queryproductlistCallV2.setData(queryproductlistBeanV2);
			queryproductlistCallV2.callService();
			Logger.verifyEquals("200", queryproductlistCallV2.getString("code"), "验证code");
			Logger.verifyNotEquals(0, queryproductlistCallV2.getJsonObject().getAsJsonObject("data").getAsJsonArray("productList").size(),"没有查询到");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_QueryProductList_016() {
		Logger.start(true, "商户-》代理，条件筛选不匹配查不到，不会自动铺货、然后删除商品");
		try {
			
			Integer MchId = GodmchManageCallService.CreateGodMch();
            Integer agenttype=GodmchManageCallService.getAgentType(MchId, 1);
            Integer AgentId = GodmchManageCallService.getAgentMchId(MchId, agenttype);
            //添加导入商品
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(MchId, "", true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			ImportAgentProductBean initImportAgentProduct = AddAgentProductCallService.initImportAgentProduct(AgentId, "", productId, MchId, false);
			String AgentProductId = AddAgentProductCallService.ImportAgentProduct(initImportAgentProduct);
			
			Thread.sleep(2000);
			queryproductlistBeanV2.setUserId(AgentId);
			queryproductlistBeanV2.setPageIndex(1);
			queryproductlistBeanV2.setPageSize(10);
			queryproductlistBeanV2.setAgentType(-1);
			queryproductlistCallV2.setData(queryproductlistBeanV2);
			queryproductlistCallV2.callService();
			Logger.verifyEquals("200", queryproductlistCallV2.getString("code"), "验证code");
			List<ProductListDto> productListDtoList2 = queryproductlistCallV2.getProductList();
			Logger.verifyEquals(productListDtoList2.get(0).getProductId(),AgentProductId, "验证productId");

			SaveSelectionConditionBean initSaveSelectionCondition = AddAgentProductCallService.InitSaveSelectionCondition(MchId, AgentId, 1);
			initSaveSelectionCondition.setBrandIdList(Arrays.asList(666));
			AddAgentProductCallService.SaveSelectionCondition(initSaveSelectionCondition);
			
			
			Thread.sleep(3000);
			queryproductlistCallV2.callService();
			Logger.verifyEquals("200", queryproductlistCallV2.getString("code"), "验证code");
			List<ProductListDto> productListDtoList = queryproductlistCallV2.getProductList();
			Logger.verifyEquals(0,productListDtoList.size(), "验证productId");
			
			
			// 查询二级代理商的商品id
			List<AgentProductPo> ap1 = ymtProductsIWapper.selectAgentProductByRootProductId(productId).stream()
								.filter(x -> x.getUserId() == AgentId)
								.collect(Collectors.toList());
			Logger.verifyEquals(-2, ap1.get(0).getAction(), "筛选后删除商品");
						
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_QueryProductList_017() {
		Logger.start(true, "商户-》代理-》分销小店，上级设置筛选之后，分销小店会移除，代理会删除");
		try {
			//创建一个商户和分销小店
			Integer MchId = GodmchManageCallService.CreateGodMch();
			GodmchManageCallService.SetVip(MchId);
			Integer AgentId = GodmchManageCallService.CreateAgent(MchId);
			Integer StoreId = GodmchManageCallService.CreateStoresByAgent(MchId,AgentId, 10);
			//创建商品，小店会继承
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(MchId, "", true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			ImportAgentProductBean importAgentProductBean = AddAgentProductCallService.initImportAgentProduct(AgentId,"",productId,MchId,false);
			String agentProductId = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean);
			Thread.sleep(5000);
			EditProductRebateBean initEditProductRebateBean = AddAgentProductCallService.initEditProductRebateBean(agentProductId,StoreId, AgentId, 20);
			AddAgentProductCallService.EditProductRebateBean(initEditProductRebateBean);
			
			Thread.sleep(2000);
			queryproductlistBeanV2.setUserId(StoreId);
			queryproductlistBeanV2.setPageIndex(1);
			queryproductlistBeanV2.setPageSize(10);
			queryproductlistBeanV2.setAgentType(-1);
			queryproductlistCallV2.setData(queryproductlistBeanV2);
			queryproductlistCallV2.callService();
			Logger.verifyEquals("200", queryproductlistCallV2.getString("code"), "验证code");
			List<ProductListDto> productListDtoList2 = queryproductlistCallV2.getProductList();
			Logger.verifyEquals(productListDtoList2.get(0).getProductId(),agentProductId, "验证productId");
			
			
			
			SaveSelectionConditionBean initSaveSelectionCondition = AddAgentProductCallService.InitSaveSelectionCondition(MchId, AgentId, 1);
			initSaveSelectionCondition.setBrandIdList(Arrays.asList(666));
			AddAgentProductCallService.SaveSelectionCondition(initSaveSelectionCondition);
			
			Thread.sleep(3000);
			queryproductlistCallV2.callService();
			Logger.verifyEquals("200", queryproductlistCallV2.getString("code"), "验证code");
			List<ProductListDto> productListDtoList = queryproductlistCallV2.getProductList();
			Logger.verifyEquals(0,productListDtoList.size(), "验证productId");
			
			
			// 查询二级代理商的商品id
			List<AgentProductPo> ap1 = ymtProductsIWapper.selectAgentProductByRootProductId(productId).stream()
								.filter(x -> x.getUserId() == AgentId)
								.collect(Collectors.toList());
			Logger.verifyEquals(-2, ap1.get(0).getAction(), "筛选后删除商品");
						
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_QueryProductList_018() {
		Logger.start(true, "商户-》代理-》代理-》分销小店，上级设置筛选之后，分销小店会查不到、中间两个代理都会移除");
		try {
			//创建一个商户和分销小店
			Integer MchId = GodmchManageCallService.CreateGodMch();
			GodmchManageCallService.SetVip(MchId);
			Integer AgentId = GodmchManageCallService.CreateAgent(MchId);
			Integer AgentId1 = GodmchManageCallService.CreateAgent(AgentId,MchId);
			System.out.println("创建分销小店");
			Integer StoreId = GodmchManageCallService.CreateStoresByAgent(MchId,AgentId1, 10);
			//创建商品，小店会继承
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(MchId, "", true);
			String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
			ImportAgentProductBean importAgentProductBean = AddAgentProductCallService.initImportAgentProduct(AgentId,"",productId,MchId,true);
			String agentProductId = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean);
			ImportAgentProductBean importAgentProductBean1 = AddAgentProductCallService.initImportAgentProduct(AgentId1,"",agentProductId,AgentId,true);
			String agentProductId1 = AddAgentProductCallService.ImportAgentProduct(importAgentProductBean1);
			
			Thread.sleep(2000);
			queryproductlistBeanV2.setUserId(StoreId);
			queryproductlistBeanV2.setPageIndex(1);
			queryproductlistBeanV2.setPageSize(10);
			queryproductlistBeanV2.setAgentType(-1);
			queryproductlistCallV2.setData(queryproductlistBeanV2);
			queryproductlistCallV2.callService();
			Logger.verifyEquals("200", queryproductlistCallV2.getString("code"), "验证code");
			List<ProductListDto> productListDtoList2 = queryproductlistCallV2.getProductList();
			Logger.verifyEquals(productListDtoList2.get(0).getProductId(),agentProductId1, "验证productId");
			
			
			
			SaveSelectionConditionBean initSaveSelectionCondition = AddAgentProductCallService.InitSaveSelectionCondition(MchId, AgentId, 1);
			initSaveSelectionCondition.setBrandIdList(Arrays.asList(666));
			AddAgentProductCallService.SaveSelectionCondition(initSaveSelectionCondition);
			
			Thread.sleep(3000);
			queryproductlistCallV2.callService();
			Logger.verifyEquals("200", queryproductlistCallV2.getString("code"), "验证code");
			List<ProductListDto> productListDtoList = queryproductlistCallV2.getProductList();
			Logger.verifyEquals(0,productListDtoList.size(), "验证productId");
			
			
			// 查询二级代理商的商品id
			List<AgentProductPo> ap1 = ymtProductsIWapper.selectAgentProductByRootProductId(productId).stream()
								.filter(x -> x.getUserId() == AgentId1)
								.collect(Collectors.toList());
			Logger.verifyEquals(-2, ap1.get(0).getAction(), "筛选后删除商品");
			
			// 查询二级代理商的商品id
			ap1 = ymtProductsIWapper.selectAgentProductByRootProductId(productId).stream()
								.filter(x -> x.getUserId() == AgentId)
								.collect(Collectors.toList());
			Logger.verifyEquals(-2, ap1.get(0).getAction(), "筛选后删除商品");
						
						
		} catch (Exception e) {
			Logger.fail(e);
		}
	}	
	
	
	
	
	

}